﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace TiDiSun
{
    public partial class Update_Sanpham_Acquy : Form
    {
        public Update_Sanpham_Acquy()
        {
            InitializeComponent();
        }

        public int id { get; set; }

        private bool SanPham_StatusThemAcQuy()
        {
            if (txtAcquy_tensanpham.Text == "Hãy nhập")
            {
                txtAcquy_tensanpham.ForeColor = System.Drawing.Color.Red;
                return false;
            }
            if (txtAcquy_soAH.Text == "Hãy nhập")
            {
                txtAcquy_soAH.ForeColor = System.Drawing.Color.Red;
                return false;
            }
            if (txtAcquy_giatien.Text == "Hãy nhập")
            {
                txtAcquy_giatien.ForeColor = System.Drawing.Color.Red;
                return false;
            }

            return true;
        }

        private void btnSanPham_ThemAcquy_Click(object sender, EventArgs e)
        {
            if (SanPham_StatusThemAcQuy())
            {
                try
                {
                    SanPham_AcQuy_DTO acquy = new SanPham_AcQuy_DTO();
                    acquy.id = id;
                    acquy.tensanpham = txtAcquy_tensanpham.Text;
                    acquy.soAH = float.Parse(txtAcquy_soAH.Text);
                    acquy.giatien = float.Parse(txtAcquy_giatien.Text);

                    AcQuyBUS.Update_sanpham_acquy(acquy);
                    this.Close();
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); }
            }
        }

        private void Update_Sanpham_Acquy_Load(object sender, EventArgs e)
        {
            try
            {
                id = int.Parse(this.Tag.ToString());
                SanPham_AcQuy_DTO acquy = new SanPham_AcQuy_DTO();
                acquy = AcQuyBUS.load_sanpham_acquy_id(id);

                txtAcquy_tensanpham.Text = acquy.tensanpham;
                txtAcquy_soAH.Text = acquy.soAH.ToString();
                txtAcquy_giatien.Text = acquy.giatien.ToString();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }

        // event text changed------------------------------------------------------------
        private void txtAcquy_tensanpham_TextChanged(object sender, EventArgs e)
        {
            txtAcquy_tensanpham.ForeColor = System.Drawing.Color.Black;
        }

        private void txtAcquy_soAH_TextChanged(object sender, EventArgs e)
        {
            txtAcquy_soAH.ForeColor = System.Drawing.Color.Black;
        }

        private void txtAcquy_giatien_TextChanged(object sender, EventArgs e)
        {
            txtAcquy_giatien.ForeColor = System.Drawing.Color.Black;
        }


        // event leave-------------------------------------------------------------
        private void txtAcquy_tensanpham_Leave(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtAcquy_tensanpham.Text))
            {
                txtAcquy_tensanpham.Text = "Hãy nhập";
                txtAcquy_tensanpham.ForeColor = System.Drawing.Color.DarkGray;
            }
        }

        private void txtAcquy_soAH_Leave(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtAcquy_soAH.Text))
            {
                txtAcquy_soAH.Text = "Hãy nhập";
                txtAcquy_soAH.ForeColor = System.Drawing.Color.DarkGray;
            }
        }

        private void txtAcquy_giatien_Leave(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtAcquy_giatien.Text))
            {
                txtAcquy_giatien.Text = "Hãy nhập";
                txtAcquy_giatien.ForeColor = System.Drawing.Color.DarkGray;
            }
        }


        // event click------------------------------------------------------------
        private void txtAcquy_tensanpham_Click(object sender, EventArgs e)
        {
            if (txtAcquy_tensanpham.Text == "Hãy nhập")
                txtAcquy_tensanpham.Text = "";
        }

        private void txtAcquy_soAH_Click(object sender, EventArgs e)
        {
            if (txtAcquy_soAH.Text == "Hãy nhập")
                txtAcquy_soAH.Text = "";
        }

        private void txtAcquy_giatien_Click(object sender, EventArgs e)
        {
            if (txtAcquy_giatien.Text == "Hãy nhập")
                txtAcquy_giatien.Text = "";
        }

        private void txtAcquy_giatien_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar) && e.KeyChar != '.')
                e.Handled = true;
        }

        private void txtAcquy_soAH_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar) && e.KeyChar != '.')
                e.Handled = true;
        }












    }
}
